#!/usr/bin/bash

#Initialize a new wallet : lotus wallet  new / new bls
#创建新 [bls] 钱包
bls_address=$(lotus wallet new bls)
echo "new bls wallet:\n\t ${bls_address}\n"
echo $(date +%Y-%m-%d" "%H:%M:%S)" new bls wallet:${bls_address}" >> ~/lotusDir/history/lotus-wallet.history

#https://faucet.testnet.filecoin.io/send
#SENDING FUNDS 发fil测试币 
address="address="${bls_address}
bls_address_sent=$(curl -d "${address}" "https://faucet.testnet.filecoin.io/send")
echo "\nsend funds:\n\t ${bls_address_sent}\n"
echo $(date +%Y-%m-%d" "%H:%M:%S)" send funds:${bls_address_sent}" >> ~/lotusDir/history/lotus-wallet.history 

#创建矿工：暂时只能在线创建
param=${address}"&sectorSize=34359738368"
#miner=$(curl -d "${param}" "https://faucet.testnet.filecoin.io/mkminer")

#提示手动创建：
echo "create storage-miner注意必须项:  
	1.请在任意pc浏览器访问 https://faucet.testnet.filecoin.io/mkminer?${param} 在线生成矿工。 \n   
	2.请多等待几分钟，直到页面返回结果 \n   
	3.将 To initialize the storage miner run the following command 取回此处输入对话框并回车 \n
To initialize the storage miner run the following command :"
read miner_init
echo $(date +%Y-%m-%d" "%H:%M:%S)  $miner_init >> ~/lotusDir/history/lotus-storage-miner-init.history
echo "\nTo initialize the storage miner run the following command: \n"$miner_init"\n\n initializing storage miner:"

rm -f ~/lotusDir/log/lotus-storage-miner-init.log
touch ~/lotusDir/log/lotus-storage-miner-init.log
nohup ${miner_init} >> ~/lotusDir/log/lotus-storage-miner-init.log 2>&1 &

echo "lotus-storage-miner init 矿工初始化中 \n 监控日志 : ~/lotusDir/log/lotus-storage-miner-init.log"